<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2018/8/24
 * Time: 17:20
 */
namespace app\api\model;

class Theme extends BaseModel {

    protected $hidden = ['topic_img_id','head_img_id','delete_time', 'update_time'];

    /**Teme表关联img表----------topic_img_id外键
     * @return \think\model\relation\BelongsTo
     */
    public function topicImg(){
        return $this->belongsTo('Image','topic_img_id','id');
    }

    /**Teme表关联img表-----------head_img_id外键
     * @return \think\model\relation\BelongsTo
     */
    public function headImg(){
        return $this->belongsTo('Image','head_img_id','id');
    }

    /**
     * Teme表与product的表之间多对多的关联关系
     * @return \think\model\relation\BelongsToMany
     */
    public function products(){
        return $this->belongsToMany('Product','theme_product','product_id','theme_id');
    }


    /**
     * 获取相关id的主题信息
     * @param $ids
     * @return false|\PDOStatement|string|\think\Collection
     */
    public static function getThemeByIDs($ids){
        return self::with(['topicImg','headImg'])->where('id','in',$ids)->select();
    }

    /**
     * 获取指定id的主题的图片信息
     * @param $id
     * @return array|false|\PDOStatement|string|\think\Model
     */
    public static function getThemeWithProducts($id){
        return self::with(['products','topicImg','headImg'])->find($id);
    }

}